package com.hqj.client.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hqj.client.entity.DownloadForm;
import com.hqj.client.mapper.DownloadFormMapper;
import com.hqj.client.service.DownloadFormService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 王建林
 * @version 1.0
 * @date 2020/10/19
 */
@Service
public class DownloadFormServiceImpl implements DownloadFormService {
    @Resource
    private DownloadFormMapper downloadFormMapper;
    /**
     * 分页查询
     * @date 2020/10/19 15:12
     * @param page
     * @param size
     * @return java.util.List<com.hqj.client.entity.DownloadForm>
     */
    @Override
    public List<DownloadForm> findPage(int page, int size) {
        Page<DownloadForm> page1 = downloadFormMapper.selectPage(new Page<>(page, size), null);
        return page1.getRecords();
    }
    /**
     * 增加
     * @date 2020/10/19 15:28
     * @param downloadForm
     * @return int
     */
    @Override
    public int add(DownloadForm downloadForm) {

        return downloadFormMapper.insert(downloadForm);
    }
    /**修改
     * @date 2020/10/19 15:37
     * @param downloadForm
     * @return int
     */
    @Override
    public int update(DownloadForm downloadForm) {

        return downloadFormMapper.updateById(downloadForm);
    }
    /**
     * 删除
     * @date 2020/10/19 15:54
     * @param id  分类id
     * @return int
     */
    @Override
    public int delete(Long id) {
        QueryWrapper<DownloadForm>wrapper=new QueryWrapper<>();
        wrapper.eq("classify_id",id);
        DownloadForm downloadForm = downloadFormMapper.selectOne(wrapper);
        downloadForm.setIsDelete(1);
        return downloadFormMapper.updateById(downloadForm);
    }
    /**
     * 搜索
     * @date 2020/10/19 16:04
     * @param fileNames
     * @return com.hqj.client.entity.DownloadForm
     */
    @Override
    public List<DownloadForm>search(String fileNames) {
        QueryWrapper<DownloadForm>wrapper=new QueryWrapper<>();
        wrapper.eq("is_delete",0).like("file_names",fileNames);
        List<DownloadForm> downloadForms = downloadFormMapper.selectList(wrapper);
        return downloadForms;
    }
}
